# @author Oliver Jan Krylow 2010
#
#

HX=../haxe


HXJVMDOC=haxejvmdoc
DOTDIR=$(HXJVMDOC)/dot
IMGDIR=$(HXJVMDOC)/images
CSSDOT=dotstyle.css
CSSDOC=docstyle.css

DATE=$(shell date +%N)

#including main makefile of haxe project
include $(HX)/Makefile

#changing some vars of main makefile ,this way we almost do not need to modify the main makefile and are free to experiment around without breaking important code
HXJVM=.
SRC=$(NEKO)/libs/include/ocaml/*.ml* *.ml* $(HX)/*.ml*

# this explicit list of source files is useful, to later iterate over it...
HXJVMSRC=jvm_type.ml jvm_bytecode.ml jvm_io.ml jvm_jar.ml

#TODO
info: 
	echo "Welcome, Commander $(USER) ! "

doc: doc_clean all
	#html documentation
	ocamldoc -d $(HXJVMDOC) -pp camlp4o.opt -stars -sort -hide-warnings -I $(EXTLIB) -I $(HX) -I $(XML) -I $(NEKO)/libs/include/ocaml -I $(EXTC) -I $(SWFLIB) -keep-code -t "HaXeJvm Documentation" -html -all-params -colorize-code -css-style $(CSSDOC) $(HXJVMSRC)
	
	#dot graphs whole haxe code base and individual haxejvm source files as pngs and (interactive?) svgs
	ocamldoc -o $(DOTDIR)/haxe.dot -pp camlp4o.opt -hide-warnings -I $(EXTLIB) -I $(HX) -I $(XML) -I $(NEKO)/libs/include/ocaml -I $(EXTC) -I $(SWFLIB) -dot -dot-reduce  $(SRC)
	dot -Grotate=0 -Gstylesheet="$(CSSDOT)" -Tpng -Tsvg -o$(IMGDIR)/haxe.png -o$(IMGDIR)/haxe.svg $(DOTDIR)/haxe.dot
	
	# loop over HXJVMSRC and generate dots and then pngs and svgs
	($(foreach sf,$(HXJVMSRC),ocamldoc -hide-warnings -o $(DOTDIR)/$(sf:.ml=.dot) -I $(EXTLIB) -I $(HX) -dot -dot-reduce -dot-colors darkorange2 -dot-types $(sf) ; dot -Grotate=0 -Gstylesheet="$(CSSDOT)" -Tpng -Tsvg -o$(IMGDIR)/$(sf:.ml=.png) -o$(IMGDIR)/$(sf:.ml=.svg) $(DOTDIR)/$(sf:.ml=.dot ;)))

#TODO:refine what files should be included in tarball
tarball: doc
	rm -f haxejvm*.tar
	tar -cf haxejvm_$(DATE).tar $(HXJVMSRC) $(HXJVMDOC)
    
google_upload: tarball
	python ~/bin/googlecode_upload.py -s "Archived source files." -p haxejvm -u okrylow -w VD3zm2py6AK4 haxejvm*.tar 

doc_clean:
	rm -rf $(HXJVMDOC)/*.* $(DOTDIR)/* $(IMGDIR)/* haxejvm*.tar

